using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using NazSoft.Framework;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Transactions;
using BCL;
using BCL.Entity.Entity;
using System.Web.UI.WebControls;

namespace BCL.Entity.Generic.DAL
{
    public partial class ResultsShowGenericDAL
    {

        #region Constructor
        public ResultsShowGenericDAL()
        { }
        #endregion

        #region Public Methods
        public List<ResultsShow> Select(ResultsShow Resultsshow, bool isCacheData = true)
        {
            string strKey = "Select" + Resultsshow.Result + Resultsshow.RollNo + Resultsshow.fatherName + Resultsshow.fName + Resultsshow.lName + Resultsshow.Marks + Resultsshow.Remarks + Resultsshow.Result_TypeID + Resultsshow.To + Resultsshow.From + (Resultsshow.SortingDirection == SortDirection.Descending ? "D" : "A") + Resultsshow.SortingField;


            List<ResultsShow> data = null;


            if (isCacheData)
            {


                data = CacheHelper.Get<List<ResultsShow>>(strKey);


                if (data != null) return data;
            }


            SqlHelper helper = new SqlHelper();


            object[] objName = { "Result", "RollNo", "fatherName", "fName", "lName", "Marks", "Remarks", "Result_TypeID", "To", "From", "SortDirection", "SortColumn" };
            object[] objValue = { Resultsshow.Result, Resultsshow.RollNo, Resultsshow.fatherName, Resultsshow.fName, Resultsshow.lName, Resultsshow.Marks, Resultsshow.Remarks, Resultsshow.Result_TypeID, Resultsshow.To, Resultsshow.From, Resultsshow.SortingDirection == SortDirection.Descending ? "D" : "A", Resultsshow.SortingField };
            DataTable dataTable = helper.GetDataTable("ResultsShow_Select", objName, objValue);
            data = CollectionHelper.ConvertTo<ResultsShow>(dataTable).ToList();
            if (isCacheData)
                CacheHelper.Add<List<ResultsShow>>(data, strKey);
            return data;
        }

        public List<ResultsShow> SelectWithOutPaging(ResultsShow Resultsshow, bool isCacheData = true)
        {
            string strKey = "SelectWithOutPaging" + Resultsshow.Result + Resultsshow.RollNo + Resultsshow.fatherName + Resultsshow.fName + Resultsshow.lName + Resultsshow.Marks + Resultsshow.Remarks + Resultsshow.Result_TypeID + (Resultsshow.SortingDirection == SortDirection.Descending ? "D" : "A") + Resultsshow.SortingField;


            List<ResultsShow> data = null;


            if (isCacheData)
            {


                data = CacheHelper.Get<List<ResultsShow>>(strKey);


                if (data != null) return data;
            }


            SqlHelper helper = new SqlHelper();


            object[] objName = { "Result", "RollNo", "fatherName", "fName", "lName", "Marks", "Remarks", "Result_TypeID", "SortDirection", "SortColumn" };
            object[] objValue = { Resultsshow.Result, Resultsshow.RollNo, Resultsshow.fatherName, Resultsshow.fName, Resultsshow.lName, Resultsshow.Marks, Resultsshow.Remarks, Resultsshow.Result_TypeID, Resultsshow.SortingDirection == SortDirection.Descending ? "D" : "A", Resultsshow.SortingField };
            DataTable dataTable = helper.GetDataTable("ResultsShow_SelectWithOutPaging", objName, objValue);
            data = CollectionHelper.ConvertTo<ResultsShow>(dataTable).ToList();
            if (isCacheData)
                CacheHelper.Add<List<ResultsShow>>(data, strKey);
            return data;
        }

        public ResultsShow Get(ResultsShow Resultsshow)
        {
            SqlHelper helper = new SqlHelper();


            object[] objName = { "RollNo", "typeId" };
            object[] objValue = { Resultsshow.RollNo, Resultsshow.Result_TypeID };
            DataTable dataTable = helper.GetDataTable("ResultStudent", objName, objValue);
            return CollectionHelper.ConvertTo<ResultsShow>(dataTable).FirstOrDefault();
        }

        public int Save(ResultsShow Resultsshow, string userName, Result_Type type)
        {
            SqlHelper helper = new SqlHelper();
            int id = 0;

            Resultsshow.CreatedBy = userName;

            Resultsshow.CreatedDate = DateTime.Now;

            Resultsshow.UpdatedBy = userName;

            Resultsshow.UpdatedDate = DateTime.Now;

            object[] objName = { "RollNo", "fatherName", "fName", "lName", "Marks", "Remarks", "IsActive", "IsDeleted", 
                                   "TotalNumber","ObtainNumber","Percentage","UserName","Title","ResultAnnocementDate",
                               "ResultYear","ResultLevel","NumberOfPaper","DisplayText"};
            object[] objValue = { Resultsshow.RollNo, Resultsshow.fatherName, Resultsshow.fName, Resultsshow.lName, Resultsshow.Marks, 
                                    Resultsshow.Remarks,
                                    Resultsshow.IsActive, Resultsshow.IsDeleted, Resultsshow.TotalNumber,Resultsshow.ObtainNumber,
                                    Resultsshow.Percentage,userName,type.Title,type.ResultAnnocementDate,type.ResultYear,type.ResultLevel,
                                    Resultsshow.NumberOfPaper,Resultsshow.DisplayText};
            int i = helper.ExecuteNonQuery("ResultInsert", objName, objValue);

            CacheHelper.ClearAll();

            return id;
        }

        public int DeleteSoft(ResultsShow Resultsshow)
        {
            SqlHelper helper = new SqlHelper();
            int id = 0;

            Resultsshow.CreatedBy = SessionHandler.UserInfo.Username;

            Resultsshow.CreatedDate = DateTime.Now;

            Resultsshow.UpdatedBy = SessionHandler.UserInfo.Username;

            Resultsshow.UpdatedDate = DateTime.Now;

            using (TransactionScope t = new TransactionScope(TransactionScopeOption.Suppress))
            {
                id = helper.OperationEntity("ResultsShow_DeleteSoft", Resultsshow, OperationMode.Delete, "");
                t.Complete();

            }

            CacheHelper.ClearAll();

            return id;
        }

        public int Delete(ResultsShow Resultsshow)
        {
            SqlHelper helper = new SqlHelper();
            int id = 0;

            Resultsshow.CreatedBy = SessionHandler.UserInfo.Username;

            Resultsshow.CreatedDate = DateTime.Now;

            Resultsshow.UpdatedBy = SessionHandler.UserInfo.Username;

            Resultsshow.UpdatedDate = DateTime.Now;

            using (TransactionScope t = new TransactionScope(TransactionScopeOption.Suppress))
            {
                id = helper.OperationEntity("ResultsShow_Delete", Resultsshow, OperationMode.Delete, "");
                t.Complete();

            }

            CacheHelper.ClearAll();

            return id;
        }

        #endregion

    }
}
